package com.atguigu.my.chapter01

/**
 *
 * @description: input测试
 * @time: 2020-05-20 17:06
 * @author: baojinlong 
 **/
object VarDemo04 {
  def main(args: Array[String]): Unit = {
    val age = 112
    // StdIn是object对象可以直接使用
    if (age > 18) {
      println("YOU-成年了")
    } else {
      println("YOU-没有成年")
    }

    val year = 2020
    if (year % 4 == 0 && year % 100 != 0) {
      printf("%d是闰年", year)
    } else {
      printf("%d不是闰年", year)
    }
    // scala中任意表达式都是有返回值的,也就意味着if else表达式其实是有返回结果的,具体返回结果的值取决于满足条件的代码体最后一行内容
    val inputAge = 20
    val res = if (inputAge > 30) {
      "yes ok"
    } else {
      41
    }
    println(" 计算结果为unit则返回()" + res)
    val start = 1
    val end = 10
    for (i <- start.to(end)) {
      println("hello" + i)
    }
    for (x <- 1 to 10) {
      println(x)
    }
    val myList = List("hello", "tom", 10, 30)
    for (elem <- myList) {
      println(elem)
    }
    for (i <- 1 until 11 if i % 2 == 0) {
      println(i)
    }
    for (i <- 1 to 10; j = 10 - i) {
      printf("i=%d j=%d \n", i, j)
    }
    for (i <- 1 to 10; j <- 20 to 30) {
      printf("i=%d j=%d \n", i, j)
    }
    println("hello")
    val resxx = for (i <- 1 to 10) yield {
      i * 3
    }
    for (elem <- resxx) {
      println(elem)
    }
    // scala擅长对集合进行处理

    for {
      i <- 1 to 10
      j <- 20 to 30
    } {
      printf("i=%d j=%d \n", i, j)
    }

    for (i <- Range(1, 10, 3)) {
      println("i=" + i)
    }
    for (i <- 1 to 10 if i % 3 == 1) {
      println("i=" + i)
    }
  }
}